<?php
/**
 * Created by PhpStorm.
 * Author: shishiwenjie
 * Date: 2018/5/19
 * Time: 14:53
 */

namespace app\home\controller;
use think\Controller;
use think\Db;
use think\Session;

class Content extends Controller
{
   function index(){
       $Mcontent= new \app\home\model\Content();
       $res=$Mcontent->select();
       $this->assign("res",$res);
       return view("content");
   }
    function details(){
        if( !session('?mobile')) {
            return $this->redirect('Users/login');
        }else{
        $Mcontent= new \app\home\model\Content();
        $res=$Mcontent->where("id",$_GET['id'])->find();
        $res2 = Db::name('liewu_jigou')->where('id',$res['jigou_id'])->find();
        $img = Db::name('jigou_img')->where('jg_id',$res2['id'])->where('status',1)->select();

        foreach($img as $k=>$v){
            $imgs[]=$v['src'];
        }
        $this->assign('res',$res);
        $this->assign('jigou',$res2);
        $this->assign('imgs',$imgs);
        return view("details");
        }
    }
    function send(){
        $res = MResume::get(function ($query) {
            $query->where('user_id', Session::get('user_id'));
        });
        if($res!=null){
        $data=[
            "user_id"=>Session::get("user_id"),
            "zhaop_id"=>$_POST['zhaop_id'],
        ];
        $res = Db::name('liewu_historylist')->insert($data);
        if($res){
            return['status'=>1,'message'=>"投递简历成功！"];
        }else{
            return['status'=>0,'message'=>"投递简历失败"];
        }
        }else{
            return['status'=>-1,'message'=>"请先完善个人简历"];
        }
    }
//导航栏查询
    function select(){
        $jobaddress=$_POST['city'];
        $jobtype=$_POST['type'];
        if($jobaddress=='全部'){
            $res = Db::name('liewu_hiring')->where('jobtype',$jobtype)->select();
            return['res'=>$res];
        }else {
            $res = Db::name('liewu_hiring')->where('jobaddress', $jobaddress)->where('jobtype', $jobtype)->select();
            return ['res' => $res];
        }
    }
}